<?php
namespace Tbf\Component\Crypto\Password\Verify;
use Tbf\Component\Crypto\Password\VerifyInterface;
/**
* 多种验证方法的集合
*/
class VerifyCollection implements VerifyInterface
{
    protected $verify_plan_list = null;
    public function __construct(array $verify_plan_list)
    {
        $this->verify_plan_list = $verify_plan_list;
    }
    public function verify($plain,$hashed)
    {
        $plan = $this->getSupportPlan($hashed);
        if ($plan===null) {
            return false;
        }

        return $plan->verify($plain,$hashed);
    }
    public function support($hashed)
    {
        $plan = $this->getSupportPlan($hashed);
        if ($plan===null) {
            return false;
        }

        return true;
    }
    protected function getSupportPlan($hashed)
    {
        foreach ($this->verify_plan_list as $verify_plan) {
            if ($verify_plan->support($hashed)) {
                return $verify_plan;
            }
        }

        return null;
    }
}
